package com.squirrel.common.controller;

import com.squirrel.common.annotation.AuthToken;
import com.squirrel.common.param.comment.CommentParam;
import com.squirrel.common.param.video.PageParam;
import com.squirrel.common.response.ResponseResult;
import com.squirrel.common.response.ResponseResultUtils;
import com.squirrel.common.response.page.PageResult;
import com.squirrel.common.service.CommentService;
import com.squirrel.common.vo.comment.CommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * CommentController 评论控制器
 * </p>
 *
 * @author 关远键
 * @since 2021/11/11 16:06
 */
@RestController
@RequestMapping("/api/comment")
@Api(tags = "评论控制器")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/getCommentByVideoId/{videoId}")
    @ApiOperation("获取评论")
    public ResponseResult<PageResult<CommentVO>> getCommentByVideoId(@PathVariable("videoId") Integer videoId, PageParam pageParam) {
        PageResult<CommentVO> result = commentService.getCommentByVideoId(videoId, pageParam);
        return ResponseResultUtils.success(result);
    }

    @GetMapping("/getCommentByUserId/{userId}")
    @ApiOperation("获取评论（用户视角）")
    @AuthToken
    public ResponseResult<PageResult<CommentVO>> getCommentByUserId(@PathVariable("userId") Integer userId, PageParam pageParam) {
        PageResult<CommentVO> result = commentService.getCommentByUserId(userId, pageParam);
        return ResponseResultUtils.success(result);
    }

    @PostMapping("/sendComment")
    @ApiOperation("发送评论（仅支持回复顶级评论）")
    @AuthToken
    public ResponseResult<Integer> sendComment(CommentParam commentParam) {
        Integer commentId = commentService.sendComment(commentParam);
        return ResponseResultUtils.success(commentId);
    }

}
